package com.beauty.dressing.module.market.presenter;

import com.beauty.dressing.common.base.BasePresenter;
import com.beauty.dressing.common.bean.BaseObserver;
import com.beauty.dressing.common.bean.BaseParse;
import com.beauty.dressing.common.bean.LeaseItemDetail;
import com.beauty.dressing.common.bean.LeaseOrderResp;
import com.beauty.dressing.module.market.presenter.contract.LeaseDetailContract;
import com.beauty.dressing.rxandroid.api.ApiManager;

import java.util.List;
import java.util.Map;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * @author xutingz
 * @E-mail xutz@xianlanba.com
 * @date 2018/04/11
 */

public class LeaseDetailPresenter extends BasePresenter implements LeaseDetailContract.Presenter {

    private LeaseDetailContract.ViewControl mViewControl;

    public LeaseDetailPresenter(LeaseDetailContract.ViewControl vcl) {
        this.mViewControl = vcl;
    }

    @Override
    public void getLeaseDetail(long sales_id) {
        ApiManager.getInstence().getShopServie().leaseDetail(sales_id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<LeaseItemDetail, Object>() {

                    @Override
                    protected void onSuccees(String message, LeaseItemDetail data, List<Object> list, BaseParse extra) {
                        if (isDestoryed) return;
                        mViewControl.onLeaseDetail(true, 200, message, data);
                    }

                    @Override
                    protected void onFailed(int code, String message, LeaseItemDetail data, List<Object> list, BaseParse extra) {
                        if (isDestoryed) return;
                        mViewControl.onLeaseDetail(false, code, message, data);
                    }
                });
    }

    @Override
    public void createLeaseOrder(long memberId, long leaseId) {
        Map<String, String> map = httpParams.getHeaderMap();
        map.put("member_id", String.valueOf(memberId));
        map.put("lease_id", String.valueOf(leaseId));
        ApiManager.getInstence().getOrderServie().createLeaseOrder(map)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<LeaseOrderResp, Object>() {

                    @Override
                    protected void onSuccees(String message, LeaseOrderResp data, List<Object> list, BaseParse extra) {
                        if (isDestoryed) return;
                        mViewControl.onLeaseOrder(true, 200, message, data);
                    }

                    @Override
                    protected void onFailed(int code, String message, LeaseOrderResp data, List<Object> list, BaseParse extra) {
                        if (isDestoryed) return;
                        mViewControl.onLeaseOrder(false, code, message, data);
                    }
                });
    }



}
